<template>
  <div class="dingdan">
    <public-com></public-com>
    <div class="dd">
      <el-table :data="datas" style="width: 100%" max-height="800">
        <el-table-column fixed prop="ticket_date" label="日期" width="150">
        </el-table-column>
        <el-table-column label="手机号" width="120">{{ tel }}</el-table-column>
        <el-table-column prop="ticket_id" label="票编号" width="220"></el-table-column>
        <el-table-column prop="ticket_name" label="入校地址" width="120"></el-table-column>
        <el-table-column prop="ticket_number" label="人数" width="120"></el-table-column>
        <el-table-column>
          <template slot-scope="scope">
            <el-button @click.native.prevent="deleteRow(scope.$index, datas)" type="text" size="small">
              移除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <footer-com></footer-com>
  </div>
</template>

<script>
import PublicCom from "@/components/PublicCom.vue";
import FooterCom from "@/components/FooterCom.vue";
import axios from "axios";
export default {
  components: {
    PublicCom,
    FooterCom,
  },
  methods: {
    deleteRow(index, rows) {
      console.log(rows[index].ticket_id)
      // rows.splice(index, 1);
      axios
        .get("api/Orders/deleteOne.do", {
          params: {
            ticket_id: rows[index].ticket_id
          },
        }).then((result) => {
          console.log(result);
        });
      axios
        .get("api/Tickets/deleteOne.do", {
          params: {
            ticket_id: rows[index].ticket_id
          },
        })
        .then((result) => {
          if (result != 0) {
            rows.splice(index, 1);
          } else {
            alert("删除失败！")
          }
          // this.datas.push(result.data);
        });
      this.$router.go(0);//刷新页面
    },
  },
  data() {
    return {
      datas: [],
      tel: '',
    };
  },
  created() {
    this.tel = this.$route.query.tel;
    console.log(this.tel);
    axios
      .get("api/Orders/getAll.do", {
        params: {
          user_phone: this.tel,
        },
      })
      .then((result) => {
        // 提取ticket_id
        for (let i in result.data) {
          axios
            .get("api/Tickets/getAll.do", {
              params: {
                ticket_id: result.data[i].ticket_id,
              },
            })
            .then((result) => {
              this.datas.push(result.data);
            });
        }
      });

  },
};
</script>
<style scoped>
.dingdan {
  background-image: url("../assets/png80.png");
  background-position-y: 2%;
}

.dd {
  width: 60%;
  height: 500px;
  margin: 0 auto;
}
</style>
